<?php

declare(strict_types=1);

namespace app\model\platform;

use app\model\member\MemberModel;
use owns\interface\OwnsModelInteface;

class FeedbackModel extends OwnsModelInteface
{
    protected $name = 'platform_feedback';

    protected $field = [];

    /**
     * 查询条件
     * @param object $query
     * @param array $param
     */
    public function scopeCustom(object $query, array $param)
    {
        //反馈类型：1咨询 2建议 3其他
        if ($feedbackType = $param['feedback_type'] ?? 0) {
            $query->where('feedback_type', $feedbackType);
        }
        //联系方式
        if ($mobile = $param['mobile'] ?? '') {
            $query->whereLike('mobile', '%' . trim($mobile) . '%');
        }
        //问题描述
        if ($problem = $param['problem'] ?? '') {
            $query->whereLike('problem', '%' . trim($problem) . '%');
        }
    }

    /**
     * 会员信息
     */
    public function member()
    {
        return $this->hasOne(MemberModel::class, 'id', 'member_id')
            ->field('id,nickname,avatar,name,mobile');
    }
}
